﻿<?xml version="1.0" encoding="utf-8"?><Articles><Article><ArticlesID>531</ArticlesID><Title>Đếm số lượng người đ&amp;#227; truy cập</Title><Body>&amp;lt;p&amp;gt;L&amp;amp;agrave;m thế n&amp;amp;agrave;o để đếm số lượng người đ&amp;amp;atilde; truy cập? b&amp;amp;agrave;i viết n&amp;amp;agrave;y sẽ trả lời cho bạn.&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;justify&amp;quot;&amp;gt;&amp;lt;font face=&amp;quot;Verdana&amp;quot;&amp;gt;&amp;lt;font size=&amp;quot;2&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Code:&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;
(global.asax)&amp;lt;/font&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;pre title=&amp;quot;code&amp;quot; class=&amp;quot;brush: csharp;&amp;quot;&amp;gt;
    // sử l&amp;amp;yacute; sự kiện Session Start
    void Session_Start()
    {
        int count_visit = 0;

        //Kiểm tra file count_visit.txt nếu kh&amp;amp;ocirc;ng tồn tại th&amp;amp;igrave;
        if(System.IO.File.Exists(Server.MapPath(&amp;amp;quot;count_visit.txt&amp;amp;quot;)) == false){
            count_visit = 1;
        }
        // Ngược lại th&amp;amp;igrave;
        else{
            // Đọc dử liều từ file count_visit.txt
            System.IO.StreamReader read = new System.IO.StreamReader(Server.MapPath(&amp;amp;quot;count_visit.txt&amp;amp;quot;));
            count_visit = int.Parse(read.ReadLine());
            read.Close();

            // Tăng biến count_visit th&amp;amp;ecirc;m 1
            count_visit ++;
        }

        // kh&amp;amp;oacute;a website
        Application.Lock();
       
        // g&amp;amp;aacute;n biến Application count_visit
        Application[&amp;amp;quot;count_visit&amp;amp;quot;] = count_visit;
       
        // Mở kh&amp;amp;oacute;a website
        Application.UnLock();
       
        // Lưu dử liệu v&amp;amp;agrave;o file count_visit.txt
        System.IO.StreamWriter writer = new System.IO.StreamWriter(Server.MapPath(&amp;amp;quot;count_visit.txt&amp;amp;quot;));
        writer.WriteLine(count_visit);
        writer.Close();
    }
    void Session_End(){

    }
    void Application_OnStart(){
       
    }
    void Application_OnEnd(){

    }
&amp;lt;/pre&amp;gt;
&amp;lt;p align=&amp;quot;justify&amp;quot;&amp;gt;&amp;lt;b&amp;gt;&amp;lt;font face=&amp;quot;Verdana&amp;quot; size=&amp;quot;2&amp;quot;&amp;gt;(main.aspx)&amp;lt;/font&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;pre title=&amp;quot;code&amp;quot; class=&amp;quot;brush: xhtml;&amp;quot;&amp;gt;
    &amp;amp;lt;%@ Page Language=&amp;amp;quot;C#&amp;amp;quot; ContentType=&amp;amp;quot;text/html&amp;amp;quot; ResponseEncoding=&amp;amp;quot;utf-8&amp;amp;quot; %&amp;amp;gt;&amp;amp;lt;!DOCTYPE html PUBLIC &amp;amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;amp;quot; &amp;amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;amp;quot;&amp;amp;gt;
    &amp;amp;lt;html xmlns=&amp;amp;quot;http://www.w3.org/1999/xhtml&amp;amp;quot;&amp;amp;gt;
    &amp;amp;lt;head&amp;amp;gt;
    &amp;amp;lt;meta http-equiv=&amp;amp;quot;Content-Type&amp;amp;quot; content=&amp;amp;quot;text/html; charset=utf-8&amp;amp;quot; /&amp;amp;gt;
    &amp;amp;lt;title&amp;amp;gt;Untitled Document&amp;amp;lt;/title&amp;amp;gt;
    &amp;amp;lt;/head&amp;amp;gt;
    &amp;amp;lt;body&amp;amp;gt;
    &amp;amp;lt;!&amp;amp;ndash;Hiển thị số người đả truy cập&amp;amp;ndash;&amp;amp;gt;
    Đả c&amp;amp;oacute; &amp;amp;lt;strong&amp;amp;gt;&amp;amp;lt;%=Application[&amp;amp;quot;count_visit&amp;amp;quot;].ToString()%&amp;amp;gt; &amp;amp;lt;/strong&amp;amp;gt; người viến thăm
    &amp;amp;lt;/body&amp;amp;gt;

    &amp;amp;lt;/html&amp;amp;gt;
&amp;lt;/pre&amp;gt;
&amp;lt;p align=&amp;quot;justify&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;justify&amp;quot;&amp;gt;&amp;lt;b&amp;gt;&amp;lt;font face=&amp;quot;Verdana&amp;quot; size=&amp;quot;2&amp;quot;&amp;gt;&amp;amp;nbsp;Download code:&amp;lt;/font&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;justify&amp;quot;&amp;gt;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;http://www.box.net/public/7yx1keovzx&amp;quot;&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;font face=&amp;quot;Verdana&amp;quot; color=&amp;quot;#226699&amp;quot; size=&amp;quot;2&amp;quot;&amp;gt;&amp;lt;u&amp;gt;http://www.box.net/public/7yx1keovzx&amp;lt;/u&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;em&amp;gt;&amp;lt;font face=&amp;quot;Verdana&amp;quot; size=&amp;quot;2&amp;quot;&amp;gt;&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
&amp;lt;span style=&amp;quot;font-weight: bold;&amp;quot;&amp;gt;Theo ThanhTam-infoworldschool&amp;lt;/span&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/em&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;</Body><CommentEnabled>True</CommentEnabled><ViewCount>0</ViewCount><ReleaseDate>10/16/2009 8:00:36 PM</ReleaseDate><TotalComment>0</TotalComment><IsMedia>False</IsMedia><IsPicture>False</IsPicture><IsVote>True</IsVote><ArticlePassword /><PostVisible>0</PostVisible><ArticlePath>/2009/10/16/Dem-so-luong-nguoi-da-truy-cap-213</ArticlePath><Approved>True</Approved><ImagePath /><CategoryId>26</CategoryId><ArrayCatID>26|25</ArrayCatID></Article></Articles>